package me.ohaga
{
	import net.flashpunk.FP;
	import net.flashpunk.World;
	import net.flashpunk.utils.Draw;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	
	public class G extends World {
		private static const Y:Number = 100;
		private static const ENDX:Number = 600;
		public static const COLOR:uint = 0xFF0000; 
		
		public function G() { super(); }
		
		private var x:Number = 0;
		
		override public function begin():void {
			super.begin();
			add(new B(0));
		}
		
		override public function update():void {
			super.update();
			if (x < ENDX && Input.check(Key.RIGHT)) {
				x = Math.min(x + 2, ENDX);
				if (x % B.W == 0) {
					add(new B(x));
					// Start fading the block to the left once the main block is completely past it
					var b:B = collidePoint("b", x-B.W/2, Y + B.H/2) as B;
					if (null != b) {
						b.start();
					}
				}
			}
			
		}
		
		override public function render():void {
			super.render();
			Draw.rect(x,Y,B.W,B.H,COLOR,1);
			
		}
		
		public function boom(b:B):void {
			FP.console.log("boom " + b.x);
			if (x - b.x < B.W*2) {
				FP.console.log("lose!");
			}
			remove(b);
		}
	}
}